/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package edu.asu.cse360.client.util;

import edu.asu.cse360.model.IngredientQuantity;
import edu.asu.cse360.model.OrderStatus;
import java.text.NumberFormat;
import java.util.Locale;
import org.joda.time.DateTime;
import org.springframework.format.datetime.DateFormatter;

/**
 * This class is responsible for the formate for the reports
 * @author nadimhoque
 */
public class Formatter {

    public static String format(Object obj){
        if(obj == null){
            return "";
        }else if(obj instanceof String){
            return obj.toString();
        }else if(obj instanceof DateTime){
            return formatDate((DateTime)obj);
        }else if(obj instanceof OrderStatus){
            return formatOrderStatus((OrderStatus)obj);
        }else if(obj instanceof IngredientQuantity){
            return formatIngredientQuantity((IngredientQuantity)obj);
        }
        return obj.toString();
    }

    private static String formatOrderStatus(OrderStatus orderStatus) {
        return orderStatus.toString().replace("_", " ");
    }

    private static String formatDate(DateTime dateTime) {
        return new DateFormatter("MM-dd-yyyy").print(dateTime.toDate(), Locale.FRENCH);
    }

    private static String formatIngredientQuantity(IngredientQuantity ingredientQuantity) {
       return ingredientQuantity.toString().replace("_", " ");
    }

    public static String formatNumber(Double num){
        if(num == null){
            return "0.0";
        }else{
            NumberFormat formatter = NumberFormat.getCurrencyInstance();
            formatter.setMaximumFractionDigits(2);
            return formatter.format(num);
        }
    }

}
